package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.dao.PermissionSettingDao;
import com.itheima.dao.RoleDao;
import com.itheima.dao.UserDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.PermissionService;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionSettingDao permissionSettingDao;

    //根据用户名查询数据库获取用户信息和关联的角色信息,同时需要查询角色关联的权限信息

    @Override
    public void add(Permission permission) {
        permissionSettingDao.add(permission);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();  //过滤查询的条件

        PageHelper.startPage(currentPage,pageSize);

        Page<Permission> page = permissionSettingDao.selectPermissionByCondition(queryString);
        long total = page.getTotal();
        List<Permission> rows = page.getResult();
        return new PageResult(total,rows);
    }

    //检查项的分页查询

    @Override
    public void deleteById(Integer id) {
        permissionSettingDao.deletePermissionById(id);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionSettingDao.findPermissionById(id);
    }

    @Override
    public List<Permission> findAll() {
        return permissionSettingDao.findAllPermission();
    }
}
